<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:60:"F:\yxl\tp5.com\public/../application/admin\view\nav\add.html";i:1561121085;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片添加 love</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <style>
        body {
            font-family:"Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif;
            font-size:16px;
            padding:5px;
        }
        .form select {
            padding: 5px;
            margin:2px 10px;
            width: 150px;
            height: 30px;
            line-height: 30px;
            border: 1px solid #D4D4D4;
        }

        a{
            color: #868686;
            cursor: pointer;
        }
        a:hover{
            text-decoration: underline;
        }
        h2{
            color: #4288ce;
            font-weight: 400;
            padding: 6px 0;
            margin: 6px 0 0;
            font-size: 28px;
            border-bottom: 1px solid #eee;
        }
        div{
            margin:8px;
        }
    </style>
</head>
<body>
<div class="layui-body">
    <!-- 内容主体区域 -->
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">是否展示 </label>
            <div class="layui-input-block">
                <input type="checkbox" id="is_visible" name="is_visible" lay-skin="switch">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序 </label>
            <div class="layui-input-block">
                <input type="text" id="sort" name="sort" lay-skin="switch">
            </div>
        </div>
        <div class="layui-upload">
            <label class="layui-form-label">图片</label>
            <button type="button" class="layui-btn" id="test1">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1">
                <p id="demoText"></p>
            </div>
        </div>
        <input type="hidden" name="path_name" id="path_name">
        <div class="layui-upload">
            <label class="layui-form-label">按钮</label>
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </form>
</div>
</body>
<script src="/static/layui/layui.js"></script>
<script>
    //var upload = layui.upload;
    //指定允许上传的文件类型
    layui.use(['upload','jquery','form'], function(){
        var upload = layui.upload;
        var jquery = layui.jquery;
        var form = layui.form;

        //普通图片上传
        upload.render({
            elem: '#test1'
            ,url: '/admin/nav/uploadLayui'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    jquery('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //上传成功
                jquery('#path_name').val(res.data.src);
                //console.log(jquery('#path_name').val());
            }
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            jquery.post("/admin/nav/add_do",data.field,function(result)
            {
                if(result.code = 1){
                    layer.msg('添加成功!');
                    window.parent.location.reload();
                }

            });
            return false;
        });

    });
</script>
</html>